﻿using EFModel;
using IServices;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xm.Controllers;

namespace Serives
{
    public class Temajor_change : Imajor_change
    {
        private readonly MyDBContext he;

        public Temajor_change(MyDBContext he)
        {
            this.he = he;
        }
        //调动添加
        public Task<int> Insert(major_change major_)
        {
            return Task.Run(() =>
            {
                he.major_change.Add(major_);
                int num = he.SaveChanges();
                    return num;
            });
        }
        //人力资源通过查询
        public Task<ResultInfo> Quer(int currentPage, int pageSize)
        {
            return Task.Run(() =>
            {
                return Task.Run(() => {
                    var con = he.human_file.Where(e=> e.human_file_status != 11&&e.human_file_status!=1);
                    var list = he.human_file
                        .Where(e => e.human_file_status != 11 && e.human_file_status != 1)
                        .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                        .ToList();
                    int cont = con.Count();
                    ResultInfo result = new ResultInfo()
                    {
                        Data = list,
                        Message = "查询数据成功",
                        Status = 200,
                        Row = cont
                    };
                    return result;
                });
            });
        }
        //人力资源查询
        public Task<human_file> Quers(int id)
        {
            return Task.Run(() =>
            {
                    return he.human_file.Find(id);
            });
        }
        //薪酬标准查询
        public Task<string> Querse()
        {
            return Task.Run(() =>
            {
                return JsonConvert.SerializeObject(he.salary_standard);
            });
        }
        //调动复核通过查询
        public Task<ResultInfo> QuerSe(int currentPage, int pageSize)
        {
            return Task.Run(() =>
            {
                return Task.Run(() => {
                    var con = he.major_change.Where(e => e.check_status == 1);
                    var list = he.major_change
                        .Where(e => e.check_status == 1)
                        .OrderBy(q => q.mch_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                        .ToList();
                    int cont = con.Count();
                    ResultInfo result = new ResultInfo()
                    {
                        Data = list,
                        Message = "查询数据成功",
                        Status = 200,
                        Row = cont
                    };
                    return result;
                });
            });
        }
        //调动模糊查询
        public Task<ResultInfo> QuerSeo(major_change major_, int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.major_change.Where(e => e.check_status == 1
                && e.new_first_kind_id == major_.new_first_kind_id
                && e.new_second_kind_id == major_.new_second_kind_id
                && e.new_third_kind_id == major_.new_third_kind_id
                && e.new_major_kind_id == major_.new_major_kind_id
                && e.new_major_id == major_.new_major_id
                && e.regist_time.Date >= major_.regist_time
                && e.regist_time.Date <= major_.check_time);
                var list = he.major_change
                .Where(e => e.check_status == 1
                && e.new_first_kind_id == major_.new_first_kind_id
                && e.new_second_kind_id == major_.new_second_kind_id
                && e.new_third_kind_id == major_.new_third_kind_id
                && e.new_major_kind_id == major_.new_major_kind_id
                && e.new_major_id == major_.new_major_id
                && e.regist_time.Date >= major_.regist_time
                && e.regist_time.Date <= major_.check_time)
                .OrderBy(q => q.mch_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //人力资源通过查询
        public Task<ResultInfo> QuerSso(human_file _File, int currentPage, int pageSize)
        {
            return Task.Run(() => {
                var con = he.human_file.Where(e => e.human_file_status != 11 && e.human_file_status != 1
                && e.first_kind_name == _File.first_kind_name
                && e.second_kind_name == _File.second_kind_name
                && e.third_kind_name == _File.third_kind_name
                && e.regist_time.Date >= _File.regist_time
                && e.regist_time.Date <= _File.check_time);
                var list = he.human_file
                    .OrderBy(q => q.huf_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                    .Where(e => e.human_file_status != 11 && e.human_file_status != 1
                    && e.first_kind_name == _File.first_kind_name
                    && e.second_kind_name == _File.second_kind_name
                    && e.third_kind_name == _File.third_kind_name
                    && e.regist_time.Date >= _File.regist_time
                    && e.regist_time.Date <= _File.check_time)
                    .ToList();
                int cont = con.Count();
                ResultInfo result = new ResultInfo()
                {
                    Data = list,
                    Message = "查询数据成功",
                    Status = 200,
                    Row = cont
                };
                return result;
            });
        }
        //调动为通过查询
        public Task<major_change> QuersTo(int id)
        {
            return Task.Run(() =>
            {
                return he.major_change.Find(id);
            });
        }
        //调动查询
        public Task<ResultInfo> QuerTo(int currentPage, int pageSize)
        {
            return Task.Run(() =>
            {
                return Task.Run(() => {
                    var con = he.major_change.Where(e=> e.check_status==0);
                    var list = he.major_change
                        .Where(e => e.check_status == 0)
                        .OrderBy(q => q.mch_id).Skip((currentPage - 1) * pageSize).Take(pageSize)
                        .ToList();
                    int cont = con.Count();
                    ResultInfo result = new ResultInfo()
                    {
                        Data = list,
                        Message = "查询数据成功",
                        Status = 200,
                        Row = cont
                    };
                    return result;
                });
            });
        }
        //调动不通过修改
        public Task<int> Update(major_change major_)
        {
            return Task.Run(() =>
            {
                major_change major = he.major_change.Find(major_.mch_id);
                major.checker = major_.checker;
                major.check_time = major_.check_time;
                major.check_reason = major_.check_reason;
                major.check_status = major_.check_status;
                int num = he.SaveChanges();
                return num;
            });
        }
        //人力资源机构职位变更
        public Task<int> UpdateDd(human_file _File)
        {
            return Task.Run(() =>
            {
                human_file _File1 = he.human_file.Find(_File.huf_id);
                _File1.human_file_status = _File.human_file_status;
                _File1.major_change_amount += _File.major_change_amount;
                int num = he.SaveChanges();
                return num;
            });
        }
        //调动人力资源查询
        public Task<string> UpdateDdTo(string id)
        {
            return Task.Run(() =>
            {
                return JsonConvert.SerializeObject(he.human_file.Where(e=> e.human_id==id));
            });
        }
        //调动通过人力资源修改
        public Task<int> UpdateTo(human_file _File)
        {
            return Task.Run(() =>
            {
                human_file _File1 = he.human_file.Find(_File.huf_id);
                _File1.first_kind_id = _File.first_kind_id;
                _File1.first_kind_name = _File.first_kind_name;
                _File1.second_kind_id = _File.second_kind_id;
                _File1.second_kind_name = _File.second_kind_name;
                _File1.third_kind_id = _File.third_kind_id;
                _File1.third_kind_name = _File.third_kind_name;
                _File1.human_major_kind_id = _File.human_major_kind_id;
                _File1.human_major_kind_name = _File.human_major_kind_name;
                _File1.human_major_id = _File.human_major_id;
                _File1.hunma_major_name = _File.hunma_major_name;
                _File1.salary_standard_id = _File.salary_standard_id;
                _File1.salary_standard_name = _File.salary_standard_name;
                _File1.salary_sum = _File.salary_sum;
                _File1.human_file_status = _File.human_file_status;
                _File1.major_change_amount += _File.major_change_amount;
                int num = he.SaveChanges();
                return num;
            });
        }
    }
}
